package cn.wit.summit.chwan.models.db;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;

import cn.wit.summit.chwan.models.dto.GameListBaseBean;
import cn.wit.summit.chwan.models.dto.GameTagInfoBean;
import cn.wit.summit.chwan.models.event.DownloadEvent;
import cn.wit.summit.chwan.tools.downloadtool.DownLoadStatusConfig;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Index;

import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.List;

/**
 * Created by Alan on 2018/3/12.
 */
@Entity(
        // Define indexes spanning multiple columns here.
        indexes = {
                @Index(value = "packageName DESC, gameId DESC", unique = true)
        }
)
public class DownLoadTaskTable implements Serializable {
    private static final long serialVersionUID=42L;
    @Id(autoincrement = true)
    private Long id;
    private int gameType;//0 android  1 obb  2 data
    private String gameId;
    private String downPath;
    private String packageName;
    private int downStatus;
    private int downprogress;
    private String downspeed;
    private String downloadUrl;
    private long totalSize;
    private String showSize;
    private long unzip_size;
    private long downStartTime;
    private String gameName;
    private int notUpdateVersion;
    private int game_down_count;
    private int ver;
    private String game_tag_info;
    private String game_info;
    private String game_ico;

    @Generated(hash = 688089346)
    public DownLoadTaskTable(Long id, int gameType, String gameId, String downPath,
            String packageName, int downStatus, int downprogress, String downspeed,
            String downloadUrl, long totalSize, String showSize, long unzip_size,
            long downStartTime, String gameName, int notUpdateVersion, int game_down_count,
            int ver, String game_tag_info, String game_info, String game_ico) {
        this.id = id;
        this.gameType = gameType;
        this.gameId = gameId;
        this.downPath = downPath;
        this.packageName = packageName;
        this.downStatus = downStatus;
        this.downprogress = downprogress;
        this.downspeed = downspeed;
        this.downloadUrl = downloadUrl;
        this.totalSize = totalSize;
        this.showSize = showSize;
        this.unzip_size = unzip_size;
        this.downStartTime = downStartTime;
        this.gameName = gameName;
        this.notUpdateVersion = notUpdateVersion;
        this.game_down_count = game_down_count;
        this.ver = ver;
        this.game_tag_info = game_tag_info;
        this.game_info = game_info;
        this.game_ico = game_ico;
    }

    @Generated(hash = 698207495)
    public DownLoadTaskTable() {
    }

    public DownloadEvent getDownEvent() {
        return new DownloadEvent(downloadUrl, downStatus, downprogress, downspeed, gameId);
    }

    public GameListBaseBean getGameListData() {
        try {
            GameListBaseBean baseBean = new GameListBaseBean();
            baseBean.setGame_id(gameId);
            baseBean.setGame_name(gameName);
            baseBean.setGame_down_load_url(downloadUrl);
            if (gameType == 0) {
                baseBean.setGame_startup_num(46);
            } else if (gameType == 2) {
                baseBean.setGame_startup_num(47);
            } else if (gameType == 1) {
                baseBean.setGame_startup_num(48);
            }
            baseBean.setGame_package_name(packageName);
            baseBean.setGame_size(showSize);
            baseBean.setGame_unzip_size(unzip_size);
            baseBean.setGame_actual_size(totalSize);
            baseBean.setGame_info(game_info);
            baseBean.setGame_down_count(game_down_count);
            baseBean.setGame_ico(game_ico);
            baseBean.setGame_ver(ver);
            Gson gson = new Gson();
            Type type = new TypeToken<List<GameTagInfoBean>>() {
            }.getType();
            List<GameTagInfoBean> gameTagInfoBeans = gson.fromJson(game_tag_info, type);
            baseBean.setGame_tag_info(gameTagInfoBeans);
            return baseBean;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new GameListBaseBean();
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public int getGameType() {
        return this.gameType;
    }

    public void setGameType(int gameType) {
        this.gameType = gameType;
    }

    public String getGameId() {
        return this.gameId;
    }

    public void setGameId(String gameId) {
        this.gameId = gameId;
    }

    public String getDownPath() {
        return this.downPath;
    }

    public void setDownPath(String downPath) {
        this.downPath = downPath;
    }

    public String getPackageName() {
        return this.packageName;
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public int getDownStatus() {
        return this.downStatus;
    }

    public void setDownStatus(int downStatus) {
        this.downStatus = downStatus;
    }

    public int getDownprogress() {
        return this.downprogress;
    }

    public void setDownprogress(int downprogress) {
        this.downprogress = downprogress;
    }

    public String getDownspeed() {
        return this.downspeed;
    }

    public void setDownspeed(String downspeed) {
        this.downspeed = downspeed;
    }

    public String getDownloadUrl() {
        return this.downloadUrl;
    }

    public void setDownloadUrl(String downloadUrl) {
        this.downloadUrl = downloadUrl;
    }

    public long getTotalSize() {
        return this.totalSize;
    }

    public void setTotalSize(long totalSize) {
        this.totalSize = totalSize;
    }

    public String getShowSize() {
        return this.showSize;
    }

    public void setShowSize(String showSize) {
        this.showSize = showSize;
    }

    public long getUnzip_size() {
        return this.unzip_size;
    }

    public void setUnzip_size(long unzip_size) {
        this.unzip_size = unzip_size;
    }

    public long getDownStartTime() {
        return this.downStartTime;
    }

    public void setDownStartTime(long downStartTime) {
        this.downStartTime = downStartTime;
    }

    public String getGameName() {
        return this.gameName;
    }

    public void setGameName(String gameName) {
        this.gameName = gameName;
    }

    public int getNotUpdateVersion() {
        return this.notUpdateVersion;
    }

    public void setNotUpdateVersion(int notUpdateVersion) {
        this.notUpdateVersion = notUpdateVersion;
    }

    public int getGame_down_count() {
        return this.game_down_count;
    }

    public void setGame_down_count(int game_down_count) {
        this.game_down_count = game_down_count;
    }

    public int getVer() {
        return this.ver;
    }

    public void setVer(int ver) {
        this.ver = ver;
    }

    public String getGame_tag_info() {
        return this.game_tag_info;
    }

    public void setGame_tag_info(String game_tag_info) {
        this.game_tag_info = game_tag_info;
    }

    public String getGame_info() {
        return this.game_info;
    }

    public void setGame_info(String game_info) {
        this.game_info = game_info;
    }

    public String getGame_ico() {
        return this.game_ico;
    }

    public void setGame_ico(String game_ico) {
        this.game_ico = game_ico;
    }


}
